<script type="text/javascript">
$(document).ready(function(){
	$("#add").on("click",function(){
		window.location.href= "${path}/expert/addHtml";
	});
	$("button[data-type='delect-button']").on("click",function(e){
		var id = $(this).attr("data-id");
		$.post("${path}/expert/delect",{expertId:id},function(data){
			if(data.success){
				location.reload();
			}
		});
	});
	$("button[data-type='editor-button']").on("click",function(e){
		var id = $(this).attr("data-id");
		window.location.href = "${path}/expert/editorHtml?expertId="+id;
	});
	
	$("#export").on("click",function(){
		location.href = "${path}/expert/export";
	});
	
	var allpro = document.getElementsByName("check");//复选框集合
	var all = document.getElementById("all");//全选按钮
	//全选
	$("input[name='all']").on("click",function(){
		 //全选按钮被选中时，遍历所有按钮
	     if (all.checked) {
	    	 for (var i = 0; i < allpro.length; i++) {
	     		if (allpro[i].type=="checkbox") {
	     			allpro[i].checked=true;
	     		}
	     	 }
	     //全选按钮未被选中时
	     }else{
	     	for (var i = 0; i < allpro.length; i++) {
	     		if (allpro[i].type=="checkbox") {
	     			allpro[i].checked=false;
	     		}
	     	}
	     }
	});
	//点击复选框，检验是否全部选中
	$("input[data-type='click-input']").on("click",function(e){
		var flag = true;
		for (var i = 0; i < allpro.length; i++) {
			if (allpro[i].type=="checkbox" && allpro[i].checked==false) {
     			all.checked = false;
     			flag = false;
     			break;
     		}
			if(flag){
				all.checked = true;
			}
		}
	});
	$("#delect").on("click",function(){
		var ids = "";
		var checkbox=$("input[name='check']");
	    for(i=0;i<checkbox.length;i++){
	        if(checkbox[i].checked){
	        	ids = ids + checkbox[i].value + ",";
	        }
	    }
	    if(ids == ""){
	    	alert("什么都没选中");
	    } else {
	    	$.post("${path}/expert/delects",{expertIds:ids},function(data){
	    		if(data.success){
	    			location.reload();
	    		}
	    	})
	    }
	})
});
</script>
<div>
	<h4>专家库</h4>
	<form action="" method="post">
		<input name="params">
		<button>查询</button>
	</form>
	<button id="add">添加</button><button id="delect">删除</button><button id="export">导出</button><br/><br>
	<table border="1">
		<tr>
			<td>全选<input type="checkbox" name="all" id="all"/></td>
			<td>序号</td>
			<td>账号</td>
			<td>姓名</td>
			<td>性别</td>
			<td>职称</td>
			<td>单位</td>
			<td>专业</td>
			<td>推荐单位</td>
			<td>状态</td>
			<td>操作</td>
		</tr>
		#foreach ($item in $list)
		<tr>    
			<td><input data-type='click-input' type="checkbox" name="check" value="${item.id}" /></td>
			<td>$!{velocityCount}: </td>
			<td>${item.name}</td>
			<td>${item.realName}</td>
			<td>#if($item.sex == 0) 男 #else 女  #end</td>
			<td>#if($item.position) ${item.position}  #else 无  #end</td>
			<td>#if($item.company) ${item.company} #else 无  #end</td>
			<td>#if($item.major) ${item.major} #else 无  #end</td>
			<td>#if($item.recom_com) ${item.recom_com}  #else 无  #end</td>
			<td>#if($item.status == 0) 启用 #else 禁用  #end</td>
			<td><button type='button' data-type='editor-button'  data-id="${item.id}">修改</button>
			<button type='button' data-type='delect-button'  data-id="${item.id}">删除</button></td>
		</tr>
		#end
	</table>
</div>